<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
function fmt_price($data)
{
    $data = $data * 100;
    $data2 = ceil($data);
    return $data2 / 100;
}

// 应用公共文件
function getshmc($id)
{
    $User = new \app\common\model\User();
    $map['id'] = $id;
    $merchant = $User->where($map)->value('merchant');
    return $merchant;
}

//生成随机字符串
function generate_rand($length = 8)
{
// 密码字符集，可任意添加你需要的字符
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|";
    $rand = "";
    for ($i = 0; $i < $length; $i++) {
// 这里提供两种字符获取方式
// 第一种是使用 substr 截取$chars中的任意一位字符；
// 第二种是取字符数组 $chars 的任意元素
// $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1);
        $rand .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $rand;
}

function put_array($arr, $filename)
{
    return file_put_contents($filename, "<?php\r\nreturn " . var_export($arr, true) . ";");
}


//获取店员级别
function getlevel($id)
{
    $cate = new \app\common\model\MerchantCate();
    $map['id'] = $id;
    $level = $cate->where($map)->value('level');
    return $level;
}

//获取代理上用户
function getsales($id)
{
    $AgentSales = new \app\common\model\AgentSales();
    $map['id'] = $id;
    $salesman = $AgentSales->where($map)->value('username');
    return $salesman;

}

//获取业务员电话
function getsalestel($id)
{
    $AgentSales = new \app\common\model\AgentSales();
    $map['id'] = $id;
    $salesman = $AgentSales->where($map)->value('tel');
    return $salesman;
}

//获取微信号认证情况
function getwxrz($value)
{
    switch ($value) {
        case "0":
            $data = "订阅号";
            break;
        case "1":
            $data = "老帐号升级后的订阅号";
            break;
        case "2":
            $data = "服务号";
            break;
        default:
            $data = "";
            break;

    }
    return $data;

}

//获取性别
function get_wx_sex($value)
{
    switch ($value) {
        case "0":
            $data = "未知";
            break;
        case "1":
            $data = "男";
            break;
        case "2":
            $data = "女";
            break;
        default:
            $data = "未知";
            break;
    }
    return $data;
}

//获取会员填写信息
function get_user_info($openid, $type = '')
{
    $CardUserGet = new \app\common\model\CardUserGet();
    $map['top_mid'] = \think\Session::get('login_top_mid');
    $map['openid'] = $openid;
    switch ($type) {

        //姓名
        case "1";
            $res = $CardUserGet->where($map)->value('name');
            break;
        //地址
        case "2";
            $res = $CardUserGet->where($map)->value('address');
            break;
        //兴趣
        case "3";
            $res = $CardUserGet->where($map)->value('habit');
            break;
        //行业
        case "4";
            $res = $CardUserGet->where($map)->value('industry');
            break;
        default;
            $res = '未知';
            break;
    }
    return $res;
}

//获取会员昵称
function get_user_nickname($openid)
{
    $CardUserGet = new \app\common\model\CardUserGet();
    $CardFans = new \app\common\model\CardFans();
    $nickname = $CardFans->where('openid', $openid)->value('nickname');
    if (empty($nickname)) {
        $nickname = $CardUserGet->where('openid', $openid)->value('nickname');
    }
    if (empty($nickname)) {
        $nickname = '未知';
    }
    return $nickname;
}

//根据openid 获取头像
function get_user_headurl($openid)
{
    $CardFans = new \app\common\model\CardFans();
    $head_url = $CardFans->where('openid', $openid)->value('head_url');
    if ($head_url) {
        $res = $head_url;
    } else {
        $res = 0;
    }
    return $res;
}

//用户分组
function get_user_group($value)
{
    $Momerchant = new \app\common\model\Momerchant();
    $CardFansGroupDict = new \app\common\model\CardFansGroupDict();
    $mab['top_mid'] = \think\Session::get('login_top_mid');
    $map['wx_open_id'] = $Momerchant->where('id', $mab['top_mid'])->value('wx_open_id');
    $map['id'] = $value;
    $res = $CardFansGroupDict->where($map)->value('group_name');
    return $res;
}


//认证状态
function getwxlx($value)
{
    switch ($value) {
        case "-1":
            $data = "未认证";
            break;
        case "0":
            $data = "微信认证";
            break;
        case "1":
            $data = "新浪微博认证";
            break;
        case "2":
            $data = "腾讯微博认证";
            break;
        case "3":
            $data = "代表已资质认证通过、还未通过名称认证";
            break;
        case "4":
            $data = "代表已资质认证通过、还未通过名称认证";
            break;
        case "5":
            $data = "已资质认证通过、还未通过名称认证，但通过了腾讯微博认证";
            break;
        default:
            $data = "";
            break;
    }
    return $data;

}

//变动类型
function getupdatetype($value)
{
    switch ($value) {
        case "1":
            $data = "充值";
            break;
        case "2":
            $data = "核销";
            break;
        case "3":
            $data = "激活";
            break;
        case "4":
            $data = "兑换";
            break;
        case "5":
            $data = "奖励";
            break;
        case "6":
            $data = "消费";
            break;
        default:
            $data = "";
            break;
    }
    return $data;
}

//获取门店名
function getmachnames($mid)
{
    $Merchant = new \app\common\model\Merchant();
    $res = $Merchant->where('id', $mid)->value('merchant');
    return $res;
}

//获取商家名称
function getmomachname($top_mid)
{
    $Momerchant = new \app\common\model\Momerchant();
    $res = $Momerchant->where(['id' => $top_mid])->value('merchant_name');
    return $res;
}

//获取会员卡名称
function getcardtitle($card_id, $type = '')
{
    if ($type == 1) {
        $CardMember = new \app\common\model\CardMember();
        $res = $CardMember->where('card_id', $card_id)->value('title');
        return $res;
//        if ($res){
//            return $res;
//        }else{
//            return '未知';
//        }
    } else {
        $CardGeneral = new \app\common\model\CardGeneral();
        $res = $CardGeneral->where('card_id', $card_id)->value('title');
        return $res;
    }

}

//获取会员卡名称
function getalicardtitle($template_id)
{
    $CardMember = new \app\common\model\CardMemberAli();
    $res = $CardMember->where('template_id', $template_id)->value('card_show_name');
    return $res;
}


//营业状态
function getmachstatu($zt)
{
    switch ($zt) {
        case 0:
            echo "营业中";
            break;
        case 1:
            echo "暂停营业";
            break;
    }
}

//获取卡券类型
function getcardtype($type)
{
    swiTch ($type) {
        case 'GROUPON':
            $rest = "团购券";
            return $rest;
            break;
        case 'CASH':
            $rest = "代金券";
            return $rest;
            break;
        case 'DISCOUNT':
            $rest = "折扣券";
            return $rest;
            break;
        case 'GIFT':
            $rest = "兑换券";
            return $rest;
            break;
        case 'GENERAL_COUPON':
            $rest = "优惠券";
            return $rest;
            break;
    }

}

//店铺名称
function getmachname($id)
{
    $map['id'] = array('in', $id);
    $Merchant = new \app\common\model\Merchant();
    $user = $Merchant->where($map)->field('merchant')->select();
    $users = [];
    foreach ($user as $k => $v) {
        $users[] = $v['merchant'];
    }
    $ss = implode(',', $users);
    return $ss;
}

//
function my_array_multisort($data, $sort_order_field, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC)
{
    foreach ($data as $val) {
        $key_arrays[] = $val[$sort_order_field];
    }
    array_multisort($key_arrays, $sort_order, $sort_type, $data);
    return $data;
}

//支付方式
function getpayfs($id)
{
    switch ($id) {
        case "0":
            $data = "微信支付";
            return $data;
            break;
        case "1":
            $data = "支付宝支付";
            return $data;
            break;
        case "2":
            $data = "微信刷卡支付";
            return $data;
            break;
        case "3":
            $data = "支付宝刷卡支付";
            return $data;
            break;
        case "4":
            $data = "现金支付";
            return $data;
            break;
        case "5":
            $data = "POS支付";
            return $data;
            break;
        case "8":
            $data = "会员卡支付";
            return $data;
            break;
        case "20":
            $data = "微信预授权";
            return $data;
            break;
        default :
            $data = "未知";
            return $data;
            break;
    }
    //   return $data;

}
function deposit_pay_status($statu){

    switch ($statu) {
        case "Y":
            $rs = "冻结中";
            break;
        case "N":
            $rs = "未支付";
            break;
        case "O":
            $rs = "已完成";
            break;
        default:
            $rs = "未知";

    }
    return $rs;

}

//支付状态
function getpaystatus($statu)
{
    switch ($statu) {
        case "0":
            $rs = "未支付";
            break;
        case "1":
            $rs = "已支付";
            break;
        case "2":
            $rs = "已退款";
            break;
        case "8":
            $rs = "订单已关闭";
            break;
        default:
            $rs = "未知";

    }
    return $rs;

}

//获取topmid下的
function getmomerchant_mid($mid)
{
    $Merchant = new \app\common\model\Merchant();
    $map['top_mid'] = $Merchant->where(['id' => $mid])->value('top_mid');
    $mach = [];
    if (isset($map['top_mid'])) {
        $mlist = $Merchant->where($map)->field('id')->select();

        foreach ($mlist as $k => $v) {
            $mach[] = $v['id'];
        }
    } else {
        $mlist = [];
    }
    $mlists = implode(',', $mach);
    return $mlists;


}

//获取rgb
function get_color_rgb($color)
{
    $color = str_replace('#', '', $color);
    if (strlen($color) > 3) {
        $rgb = array(
            'r' => hexdec(substr($color, 0, 2)),
            'g' => hexdec(substr($color, 2, 2)),
            'b' => hexdec(substr($color, 4, 2))
        );
    } else {
        $r = substr($color, 0, 1) . substr($color, 0, 1);
        $g = substr($color, 1, 1) . substr($color, 1, 1);
        $b = substr($color, 2, 1) . substr($color, 2, 1);
        $rgb = array(
            'r' => hexdec($r),
            'g' => hexdec($g),
            'b' => hexdec($b)
        );
    }
    return $rgb;
}

//获取门店数量
function get_mid_num()
{
    $Base = new \app\common\controller\AdminBase();
    $res = $Base->get_mid_num();
    return $res;
}

//获取卡券类型 （根据card_id）
function get_cardid_type($card_id)
{
    $CardGeneral = new \app\common\model\CardGeneral();
    $type = $CardGeneral->where('card_id', $card_id)->value('card_type');
    $card_type = getcardtype($type);
    return $card_type;
}

//获取卡券类型
function get_cardid_type_lden($card_id)
{
    $CardGeneral = new \app\common\model\CardGeneral();
    $type = $CardGeneral->where('card_id', $card_id)->value('card_type');
    return $type;
}

//获取商品名称
function get_goods_info($id, $type)
{
    $CardGoods = new \app\common\model\CardGoods();
    $goods = $CardGoods->where('id', $id)->find();
    if ($goods) {
        switch ($type) {
            case '1':
                $res = $goods['goods_name'];
                break;
            case '2':
                $res = $goods['goods_img'];
                break;
            default:
                $res = '未知';
        }
    } else {
        $res = '未知';
    }
    return $res;
}

//用户级别
function get_dice_item($id)
{
    $level = new \app\common\model\DictItem();
    $res = $level->where('value', $id)->value('text');
    return $res;
}

function getsignkey($appid)
{

    $Agent = new \app\common\model\Agent();
    $signkey = $Agent->where(array('sign_appid' => $appid))->value('sign_key');
    return $signkey;
}



//function uni_array($arr)
//{
//    foreach ($arr as $k => $v) {
//        if (!$v)
//            unset($arr[$k]);
//    }
//    return $arr;
//}
//
//function getsign($arrdata, $method = "sha1", $appid = "")
//{
//    try {
//        if (!function_exists($method)) return false;
//        ksort($arrdata);
//        $paramstring = "";
//        foreach ($arrdata as $key => $value) {
//            if (isset($value) && !empty($value)) {
//                if (is_array($value)) {
//                    $value = json_encode($value, JSON_UNESCAPED_UNICODE);
//                }
//                $str[] = $key . "=" . $value;
//            }
//        }
//        $paramstring = join("&", $str);
//        if (!empty($appid)) {
//            $signkey = getsignkey($appid);
//        } else {
//            $signkey = getsignkey($arrdata['appid']);
//        }
//        $Sign = $method($paramstring . "&key=" . $signkey);
//
//        return $Sign;
//    } catch (\Exception $e) {
//        return $e;
//    }
//}

function uni_array($arr)
{
    foreach ($arr as $k => $v) {
        if ($v!=0 or $v !='0') {
            if (!$v)
                unset($arr[$k]);
        }
    }
    return $arr;
}

function getsign($arrdata, $method = "sha1", $appid = "")
{
    try {
        if (!function_exists($method)) return false;
        ksort($arrdata);
        $paramstring = "";
        foreach ($arrdata as $key => $value) {
            if (isset($value) && !empty($value) or $value == '0') {
                if (is_array($value)) {
                    $value = json_encode($value, JSON_UNESCAPED_UNICODE);
                }
                $str[] = $key . "=" . $value;
            }
        }
        $paramstring = join("&", $str);
        if (!empty($appid)) {
            $signkey = getsignkey($appid);
        } else {
            $signkey = getsignkey($arrdata['appid']);
        }
        $Sign = $method($paramstring . "&key=" . $signkey);

        return $Sign;
    } catch (\Exception $e) {
        return $e;
    }
}

//是否关注
function getfollowstatu($openid)
{
    $CardFans = new \app\common\model\CardFans();
    $statu = $CardFans->where(['openid' => $openid])->value('statu');
    if ($statu == 1) {
        $res = '已关注';
    } else {
        $res = '未关注';
    }
    return $res;
}

//是否手机
function is_mobile()
{
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
        return false;

    //此条摘自TPM智能切换模板引擎，适合TPM开发
    if (isset ($_SERVER['HTTP_CLIENT']) && 'PhoneClient' == $_SERVER['HTTP_CLIENT'])
        return false;
    //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
        //找不到为flase,否则为false
        return stristr($_SERVER['HTTP_VIA'], 'wap') ? false : false;
    //判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array(
            'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile'
        );
        //从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return false;
        }
    }
    //协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT'])) {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return false;
        }
    }
    return true;
}


//获取WxOpenID
function get_wxopen_id($mid)
{
    $Merchant = new \app\common\model\Merchant();
    $bintype = $Merchant->where('id', $mid)->value('is_binding');
    $WxOpen = new \app\common\model\WxOpen();
    if ($bintype == 0) {
        $top_mid = $Merchant->where('id', $mid)->value('top_mid');
        $wxopenid = $WxOpen->where('top_mid', $top_mid)->value('id');
    } else {
        $wxopenid = $WxOpen->where('mid', $mid)->value('id');
    }
    return $wxopenid;
}

//获取用户级别
function getuserlevel($value)
{
    $map['type_id'] = 4;
    $map['value'] = $value;
    $DictItem = new \app\common\model\DictItem();
    $name = $DictItem->where($map)->value('text');
    return $name;

}

//获取商户ID
function getmid($merchant)
{
    $map['merchant'] = $merchant;
    $Merchant = new \app\common\model\Merchant();
    $mid = $Merchant->where($map)->value('id');
    return $mid;
}

//获取门店名称
function getmerchant($mid)
{
    $map['id'] = $mid;
    $Merchant = new \app\common\model\Merchant();
    $name = $Merchant->where($map)->value('merchant');
    return $name;
}

//获取代理商名称
function getagentname($id)
{
    $Agent = new \app\common\model\Agent();
    $Agentname = $Agent->where(['id' => $id])->value('name');
    return $Agentname;


}

//获取业务员名称
function getagentsales($id, $aid)
{
    $map['id'] = $id;
    $map['agent'] = $aid;
    $AgentSales = new \app\common\model\AgentSales();
    $name = $AgentSales->where($map)->value('username');
    return $name;
}

//获取人员列表信息
function getcashierinfo($arr, $type)
{
    switch ($type) {
        case '1':
            $MerchantCashier = new \app\common\model\MerchantCashier();
            $res = $MerchantCashier->where(['uid' => $arr])->value('head_url');
            return $res;
            break;
        case '2';
            $MerchantCashier = new \app\common\model\MerchantCashier();
            $res = $MerchantCashier->where(['uid' => $arr])->value('nickname');
            return $res;
            break;
        case '3';
            $MerchantCashier = new \app\common\model\MerchantCashier();
            $res = $MerchantCashier->where(['uid' => $arr])->value('gonghao');
            return $res;
            break;
        case '4';
            $Merchant = new \app\common\model\Merchant();
            $res = $Merchant->where(['id' => $arr])->value('merchant');
            return $res;
            break;
        case '5';
            $MerchantCashier = new \app\common\model\MerchantCashier();
            $res = $MerchantCashier->where(['uid' => $arr])->value('tel');
            return $res;
            break;
    }
}


//获取数据记录中json的值
function getcardinfo($id, $type = '')
{
    $CardMember = new \app\common\model\CardMember();
    $CardGeneral = new \app\common\model\CardGeneral();
    swiTch ($type) {
        case '0':
            $res = $CardMember->where('id=' . $id)->value('base_info');
            $res = json_decode($res, true);
            $rest = $res['logo_url'];
            return $rest;
            break;
        case '1':
            $res = $CardMember->where('id=' . $id)->value('title');
            $rest = $res;
            return $rest;
            break;
        case '2':
            $res = $CardMember->where('id=' . $id)->value('base_info');
            $res = json_decode($res, true);
            $rest = $res['brand_name'];
            return $rest;
            break;
        case '3':
            $res = $CardGeneral->where('id=' . $id)->value('base_info');
            $res = json_decode($res, true);
            $rest = $res['logo_url'];
            return $rest;
            break;
        case '4':
            $res = $CardGeneral->where('id=' . $id)->value('title');
            $rest = $res;
            return $rest;
            break;
        case '5':
            $res = $CardGeneral->where('id=' . $id)->value('base_info');
            $res = json_decode($res, true);
            $rest = $res['brand_name'];
            return $rest;
            break;
    }
}

//获取数据记录中json的值
function cardgetinfo($card_id, $card = '', $type = '')
{
    $CardMember = new \app\common\model\CardMember();
    $CardGeneral = new \app\common\model\CardGeneral();
    $map['card_id'] = $card_id;
    if ($card == 0) {
        switch ($type) {
            case "0":
                $res = $CardMember->where($map)->value('logo_url');
                return $res;
                break;
            case "1":
                $res = $CardMember->where($map)->value('title');
//                $res = json_decode($res, true);
//                $res = $res['title'];
                return $res;
                break;
            case "2":
                $res = $CardMember->where($map)->value('brand_name');
//                $res = json_decode($res, true);
//                $res = $res['brand_name'];
                return $res;
                break;
        }
    }
    if ($card == 1) {
        switch ($type) {
            case "0":
                $res = $CardGeneral->where($map)->value('logo_url');
                return $res;
                break;
            case "1":
                $res = $CardGeneral->where($map)->value('title');
//                $res = json_decode($res, true);
//                $res = $res['title'];
                return $res;
                break;
            case "2":
                $res = $CardGeneral->where($map)->value('brand_name');
//                $res = json_decode($res, true);
//                $res = $res['brand_name'];
                return $res;
                break;
            case "3":
                $res = $CardGeneral->where($map)->value('color');
                return $res;
                break;
        }

    }

}

//获取真实色值
function getcolor($arr)
{

    switch ($arr) {
        //浅绿
        case "Color010":
            $res = '#63b359';
            return $res;
            break;
        //
        case "Color020":
            $res = '#2c9f67';
            return $res;
            break;
        //
        case "Color030":
            $res = '#509fc9';
            return $res;
            break;
        //
        case "Color040":
            $res = '#5885cf';
            return $res;
            break;
        //
        case "Color050":
            $res = '#9062c0';
            return $res;
            break;
        //
        case "Color060":
            $res = '#d09a45';
            return $res;
            break;
        //
        case "Color070":
            $res = '#e4b138';
            return $res;
            break;
        //
        case "Color080":
            $res = '#ee903c';
            return $res;
            break;
        //
        case "Color081":
            $res = '#f08500';
            return $res;
            break;
        //
        case "Color082":
            $res = '#a9d92d';
            return $res;
            break;
        //
        case "Color090":
            $res = '#dd6549';
            return $res;
            break;
        //
        case "Color100":
            $res = '#cc463d';
            return $res;
            break;
        //
        case "Color101":
            $res = '#cf3e36';
            return $res;
            break;
        //
        case "Color102":
            $res = '#5E6671';
            return $res;
            break;
    }

}

function getgivecardnew($card_id, $type)
{
    $CardGeneral = new \app\common\model\CardGeneral();
    if ($card_id !== '' && $card_id !== null) {
        $s = json_decode($card_id, true);
//        var_dump($s);
//        return $s;
        $ss = "";
//        return json_encode($s);
        foreach ($s as $k => $v) {
            $ss .= $v['zs_card_id'] . ",";
        }
        $map['card_id'] = rtrim($ss, ',');
    }
    if ($type == 0) {
        switch ($type) {
            case "0":
                $resu = '';
                if ($card_id !== '' && $card_id !== null) {
                    $s = json_decode($card_id, true);
                    $ss = "";
                    foreach ($s as $k => $v) {
                        $ss .= $v['zs_card_id'] . "|" . $v['zs_no'] . ",";
                    }

                    $card_id_list = explode(',', rtrim($ss, ','));


                    foreach ($card_id_list as $ks => $vs) {
                        $ivs = explode('|', $vs);

                        if (filteroffcard($ivs[0]) == true && filteriscgive($ivs[0]) == true) {

                            $res[$ks]['title'] = $CardGeneral->where('card_id', $ivs[0])->value('title');
                            $res[$ks]['zs_no'] = $ivs[1];
                        }

                    }
                    if (!isset($res)) {
                        $res = [];
                    }

//                    $resu = '';
                    if (count($res) >= 1) {
                        $resu = '赠卡券：';
                        if (isset($res)) {
                            foreach ($res as $k => $v) {
                                $resu .= $v['title'] . "(" . $v['zs_no'] . "张),";
                            }
                            $resu = rtrim($resu, ',');
                        }
                    }
                }

                return $resu;
                break;
            case "1":
                $res = $CardGeneral->where($map)->value('base_info');
                $res = json_decode($res, true);
                $res = $res['brand_name'];
                return $res;
                break;
        }
    }


}

//冲送规则
function getgivecard($card_id, $type, $cards_id = "")
{
    $CardGeneral = new \app\common\model\CardGeneral();
    $map['card_id'] = ['in', $card_id];
    if ($type == 0) {
        switch ($type) {
            case "0":
                $card_id_list = explode(',', $card_id);

                foreach ($card_id_list as $k => $v) {
                    if (filteroffcard($v) == true && filteriscgive($v) == true) {
//                        var_dump($v);
                        $res[$k] = $CardGeneral->where('card_id', $v)->value('title');
                    }
                }
//               $res = $CardGeneral->where($map)->column('title');
                if (isset($res)) {
                    if (count($res) > 1) {
                        $resu = implode(',', $res);
                    } else {
                        $resu = implode(' ', $res);
                    }
                    $resu = '赠卡券:' . $resu;
                } else {
                    $resu = '';
                }

                return $resu;
                break;
            case "1":
                $res = $CardGeneral->where($map)->value('base_info');
                $res = json_decode($res, true);
                $res = $res['brand_name'];
                return $res;
                break;
        }
    }
}

function getpaygive($arr)
{
    $arr = json_decode($arr, JSON_UNESCAPED_UNICODE);
    $CardGeneral = new \app\common\model\CardGeneral();
    foreach ($arr as $k => $v) {
        $datas[$k] = $CardGeneral->where(['card_id' => $v['zs_card_id']])->value('title') . '[' . $v['zs_no'] . '张' . ']';
    }
    if ($datas) {
        $data = implode(',', $datas);
    } else {
        $data = '';
    }
    return $data;
}


//根据规则ID获取赠送卡券
function getgiveidcard($id)
{
    $CardCzgive = new \app\common\model\CardCzgive();
    $card_id = $CardCzgive->where(['id' => $id])->value('zs_card_id');
    $CardGeneral = new \app\common\model\CardGeneral();
    if (isset($card_id)) {
        $card_id_list = explode(',', $card_id);
        foreach ($card_id_list as $k => $v) {
            $res[$k] = $CardGeneral->where('card_id', $v)->value('title');
        }
        if (count($res) > 1) {
            $resu = implode(',', $res);
        } else {
            $resu = implode(' ', $res);
        }
        $resu = '赠卡券:' . $resu;
    } else {
        $resu = '';
    }
    return $resu;
}

//计次卡获取适用门店
function getcardusstore($store)
{
    if ($store !== '' && $store !== null) {
        $storelist = json_decode($store, true);
        $Mechant = new \app\common\model\Merchant();
        foreach ($storelist as $k => $v) {
            $name[$k] = $Mechant->where(['id' => $v])->value('merchant');
        }
        $res = implode(',', $name);
    } else {
        $res = '';
    }
    return $res;
}

//卡券领取/核销   (暂废弃 项目搜索未找到引用，)
function getcardgelcon($card_id, $type)
{
    switch ($type) {
        //领取数量
        case "0":
            $CardUserGet = new \app\common\model\CardUserGet();
            $resu = $CardUserGet->where('card_id', $card_id)->count('id');
            return $resu;
            break;
        //核销数量
        case "1":
            $CardConsume = new \app\common\model\CardConsume();
            $resu = $CardConsume->where('card_id', $card_id)->count('id');
            return $resu;
            break;
    }
}

//会员卡领取
function getcarduscon($card_id, $type)
{
    switch ($type) {
        //领取数量
        case "0":
            $CardUserGet = new \app\common\model\CardUserGet();
            $resu = $CardUserGet->where('card_id', $card_id)->count('id');
            return $resu;
            break;
    }
}

//卡券信息
function getcardgel($card_id, $type)
{
    $CardGeneral = new \app\common\model\CardGeneral();
    $map['card_id'] = ['in', $card_id];
    if ($type == 0) {
        switch ($type) {
            case "0":
                $resu = $CardGeneral->where('card_id', $card_id)->value('title');
                return $resu;
                break;
            case "1":
                $res = $CardGeneral->where($map)->value('base_info');
                $res = json_decode($res, true);
                $res = $res['brand_name'];
                return $res;
                break;
        }
    }
}

//获取会员卡级别
function getlive($card_id, $bonus)
{
    $map['card_id'] = $card_id;
    $CardRank = new \app\common\model\CardRank();
    $res = $CardRank->where($map)->order('bonus desc')->field('bonus,live')->select();
    foreach ($res as $k => $v) {
        if ($v['bonus'] < $bonus) {
            $sdata[] = $v['live'];
        }
    }
    if (empty($sdata[0])) {
        $sdata[0] = 0;
    }
    return $sdata[0];
}

//获取会员卡级别
function getlivename($card_id, $bonus)
{
    $map['card_id'] = $card_id;
    $CardRank = new \app\common\model\CardRank();
    $res = $CardRank->where($map)->order('bonus desc')->field('bonus,live_title')->select();
    foreach ($res as $k => $v) {
        if ($v['bonus'] < $bonus) {
            $sdata[] = $v['live_title'];
        }
    }
    if (empty($sdata[0])) {
        $sdata[0] = 0;
    }
    return $sdata[0];
}

//获取会员等级名称
function getrankname($card_id, $bonus)
{
    $map['card_id'] = $card_id;
    $CardRank = new \app\common\model\CardRank();
    $res = $CardRank->where($map)->order('bonus desc')->field('bonus,live_title,live')->select();
    foreach ($res as $k => $v) {
        if ($bonus >= $v['bonus']) {
            $sdata[] = $v['live_title'];
        }
    }
    if (!isset($sdata[0])) {
        $sdata[0] = '查看';
    }
    if (isset($sdata)) {
        $level = $sdata[0];
    } else {
        $level = '查看';
    }
    return $level;
}

//等级判断
function is_rank($arr)
{
    $CardRank = new \app\common\model\CardRank();
    $map['id'] = $arr['lid'];
    $rank = $CardRank->where($map)->find();
    if ($rank['bonus'] <= $arr['user_bonus']) {
        $data = 0;      //达到
    } else {
        $data = 1;      //未达到
    }
    return $data;
}

function rankRewardStatu($arr)
{
    $CardRank = new \app\common\model\CardRank();
    $rank = $CardRank->where(['id' => $arr['lid']])->find();
    if ($rank['reward_bonus'] > 0 || $rank['reward_balance'] > 0) {
        $CardUserGet = new \app\common\model\CardUserGet();
        $user = $CardUserGet->where(['id' => $arr['gid']])->field('bonus,rank_lock')->find();
        if ($rank['bonus'] <= $user['bonus']) {
            if ($user['rank_lock'] < $rank['live']) {
                $data = 6;              //未领取
            } else {
                $data = 7;          //已领取
            }
        } else {
            $data = 8;          //未达到
        }
    } else {
        $data = 9;          //无奖励
    }
    return $data;
}

//获取母商户
function getmomach($top_mid, $type = '')
{
    $Momerchant = new \app\common\model\Momerchant();
    $map['id'] = $top_mid;
    $info = $Momerchant->where($map)->find();
    switch ($type) {
        case "name":
            return $info['merchant_name'];
            break;
    }
}

//获取卡券可领数量
function getcardgetsume($card_id)
{
    $CardGeneral = new \app\common\model\CardGeneral();
    $base_info = $CardGeneral->where(['card_id' => $card_id])->value('base_info');
    $base = json_decode($base_info, true);
    $get_sum = $base['get_limit'];
    return $get_sum;
}

//获取卡券已领取数量
function getcardgetuser($card_id, $openid)
{
    $CardUserGet = new \app\common\model\CardUserGet();
    $sume = $CardUserGet->where(['card_id' => $card_id, 'openid' => $openid])->count('id');
    return $sume;
}

//获取有效期
function getterm($arr)
{

    switch ($arr['type']) {
        case "DATE_TYPE_PERMANENT":
            $res = '永久有效';
            break;
        //
        case "DATE_TYPE_FIX_TIME_RANGE":
            $res = date("Y-m-d", $arr['end_timestamp']);
            break;
    }
    return $res;
}

//获取订单信息
function getorder($arr, $type)
{
    $map['id'] = $arr;
    $CardGoogs = new \app\common\model\CardGoods();
    switch ($type) {
        case "0":
            $res = $CardGoogs->where($map)->value('img');
            break;
        case "1":
            $res = $CardGoogs->where($map)->value('name');
            break;

    }
    return $res;
}

//过滤购买券
function filterispay($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $card = $CardGel->where('card_id', $card_id)->field('is_pay')->find();
    if ($card['is_pay'] == 0) {
        $res = false;
    } else {
        $res = true;
    }
    return $res;
}

//过滤冲送券
function filteriscgive($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $card = $CardGel->where('card_id', $card_id)->field('is_cgive')->find();
    if ($card['is_cgive'] == 0) {
        $res = false;
    } else {
        $res = true;
    }
    return $res;
}

//过滤过期/无库存卡券
function filteroffcard($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $card = $CardGel->where('card_id', $card_id)->field('end_timestamp,stocks,consume')->find();
    $time = time();
    if ($card['end_timestamp'] < $time && $card['end_timestamp'] !== 2018040900) {
        $res = false;
    } else {
        if ($card['stocks'] > 0) {
            $res = true;
        } else {
            $res = false;
        }
    }
    return $res;
}

//过滤过期
function filtergqcard($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $card = $CardGel->where('card_id', $card_id)->field('end_timestamp,stocks,consume')->find();
    $time = time();
    if ($card['end_timestamp'] < $time && $card['end_timestamp'] !== 2018040900) {
        $res = false;
    } else {
        $res = true;
    }
    return $res;
}

//返回日期
function filtergqcards($card_id, $get_time = 0)
{
    $CardGel = new \app\common\model\CardGeneral();
    $card = $CardGel->where('card_id', $card_id)->field('end_timestamp,stocks,consume,fixed_term')->find();
    $time = time();
    if ($card['end_timestamp'] < $time && $card['end_timestamp'] !== 2018040900) {
        $res = false;
    } else {
        if ($card['end_timestamp'] == 2018040900) {
            $fixed_term = $card['fixed_term'] * 86400;
            $end_time = $fixed_term + $get_time;
            $res = date('Y-m-d H:i', $end_time);
        } else {
            $res = date('Y-m-d H:i', $card['end_timestamp']);
        }
    }
    return $res;
}

//获取卡券的抵扣状态
function filtercarddedu($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $is_dedu_cards = $CardGel->where('card_id', $card_id)->value('is_dedu_cards');
    if ($is_dedu_cards == 0) {
        $res = false;
    } else {
        $res = true;
    }
    return $res;
}

//获取卡券叠加抵扣状态
function filtercarddedupile($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $is_dedu_cards = $CardGel->where('card_id', $card_id)->value('is_dedu_cards_pile');
    if ($is_dedu_cards == 0) {
        $res = false;
    } else {
        $res = true;
    }
    return $res;
}

//获取折扣券的折扣
function getcardgeldis($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $discount = $CardGel->where('card_id', $card_id)->value('discount');
    if ($discount) {
        $res = $discount;
    } else {
        $res = 100;
    }
    return $res;
}

//获取代金券抵扣
function getcardgelcash($card_id)
{
    $CardGel = new \app\common\model\CardGeneral();
    $cost = $CardGel->where('card_id', $card_id)->field('least_cost,reduce_cost')->find();
    if ($cost) {
        $res = $cost;
    } else {
        $res = 0;
    }
    return $res;
}

//根据openid / card_id 获取用户卡号
function getcodeopenid($openid, $card_id = '')
{
    $CardUserGer = new \app\common\model\CardUserGet();
    $map['openid'] = $openid;
    if (isset($card_id)) {
        $map['card_id'] = $card_id;
    }
    $code = $CardUserGer->where($map)->value('code');
    if ($code) {
        return $code;
    } else {
        return '未获取';
    }
}

//根据openid 获取昵称
function getnicknameopenid($openid)
{
    $CardUserGer = new \app\common\model\CardUserGet();
    $map['openid'] = $openid;
    $nickname = $CardUserGer->where($map)->value('nickname');
    if ($nickname) {
        $res = $nickname;
    } else {
        $CardFans = new \app\common\model\CardFans();
        $nickname = $CardFans->where($map)->value('nickname');
        if ($nickname) {
            $res = $nickname;
        } else {
            $res = '未获取';
        }
    }
    return $res;
}

//根据openid 获取昵称
function getnameuser_id($user_id)
{
    $CardUserGer = new \app\common\model\CardUserGetAli();
    $map['user_id'] = $user_id;
    $name = $CardUserGer->where($map)->value('name');
    if ($name) {
        $res = $name;
    } else {
        $res = '未获取';
    }
    return $res;
}

//获取推荐人姓名
function getsharename($outerstr)
{
    $CardUserGer = new \app\common\model\CardUserGetAli();
    $map['outerstr'] = $outerstr;
    $name = $CardUserGer->where($map)->value('name');
    if ($name) {
        $res = $name;
    } else {
        $res = '未获取';
    }
    return $res;
}


/*
 * 获取充值金额  消费金额   type
 *
 * 参数
 * 领取id
 */
function getmoneygetid($id, $type)
{
    $CardUserUpdate = new \app\common\model\CardUserUpdate();
    $CardUserGet = new \app\common\model\CardUserGet();
    $user = $CardUserGet->where(['id' => $id])->field('card_id,code,openid')->find();
    switch ($type) {
        case 1:
            $res = $CardUserUpdate->where(['openid' => $user['openid'], 'code' => $user['code']])->sum('add_balance');
            break;
        case 2:
            $res = $CardUserUpdate->where(['openid' => $user['openid'], 'code' => $user['code']])->sum('del_balance');
            break;
        default:
            $res = '0';
            break;
    }
    return $res;
}

/*
 * 获取充值金额 支付宝  消费金额   type
 *
 * 参数
 * 领取id
 */
function getmoneygetidali($id, $type)
{
    $CardUserUpdate = new \app\common\model\CardUserUpdateAli();
    $CardUserGet = new \app\common\model\CardUserGetAli();
    $user = $CardUserGet->where(['id' => $id])->field('template_id,code,user_id')->find();
    switch ($type) {
        case 1:
            $res = $CardUserUpdate->where(['user_id' => $user['user_id'], 'code' => $user['code']])->sum('add_balance');
            break;
        case 2:
            $res = $CardUserUpdate->where(['user_id' => $user['user_id'], 'code' => $user['code']])->sum('del_balance');
            break;
        default:
            $res = '0';
            break;
    }
    return $res;
}


/*
 * 获取推荐人
 * 参数
 * outerstr
 *
 */
function getshareouter($outer)
{
    $CardShareUser = new \app\common\model\CardShareUser();
    $res = $CardShareUser->where(['outerstr' => $outer])->value('openid');
    if (!$res) {
        $res = '未获取';
    }
    return $res;
}

//获取激活字段选中状态
function getfirefield($card_id, $type)
{
    $CardMember = new \app\common\model\CardMember();
    $cardinfo = $CardMember->where(['card_id' => $card_id])->value('activatef');
    $fireinfo = json_decode($cardinfo, JSON_UNESCAPED_UNICODE);
    $firefield = [];
    if (isset($fireinfo['required_form']['common_field_id_list'])) {
        $firefield['1'] = $fireinfo['required_form']['common_field_id_list'];   //必填选定字段
    } else {
        $firefield['1'] = [];
    }
    if (isset($fireinfo['required_form']['custom_field_list'])) {
        $firefield['2'] = $fireinfo['required_form']['custom_field_list'];   //必填自定义字段
    } else {
        $firefield['2'] = [];
    }
    if (isset($fireinfo['optional_form']['common_field_id_list'])) {
        $firefield['6'] = $fireinfo['optional_form']['common_field_id_list'];   //选填选定字段
    } else {
        $firefield['6'] = [];
    }
    if (isset($fireinfo['optional_form']['custom_field_list'])) {
        $firefield['7'] = $fireinfo['optional_form']['custom_field_list'];   //选填自定义字段
    } else {
        $firefield['7'] = [];
    }
    $fireinfo = array_merge($firefield['1'], $firefield['2'], $firefield['6'], $firefield['7']);
    if ($fireinfo) {
        foreach ($fireinfo as $k => $v) {
            if ($type == $v) {
                $res = 1;
                return $res;
            } else {
                $res = 0;
            }
        }
    } else {
        $res = 0;
    }
    return $res;
}

//统计卡券核销数量

function getcardshx($card_id)
{
    $CardConsume = new \app\common\model\CardConsume();
    $map['card_id'] = $card_id;
//    $map['have'] = 1;
//    $map['statu'] = 2;
    $sum = $CardConsume->where($map)->count('id');
    return $sum;
}

//统计卡券领取数量
function getcardsget($card_id)
{
    $CardUserGet = new \app\common\model\CardUserGet();
    $map['card_id'] = $card_id;
//    $map['have'] = 1;
//    $map['statu'] = 2;
    $sum = $CardUserGet->where($map)->count('id');
    return $sum;
}

function getbdtype($type)
{
    switch ($type) {
        case "1";
            $res = 'add';
            break;
        case "2";
            $res = 'del';
            break;
        case "3";
            $res = 'fire';
            break;
        case "4";
            $res = 'dh';
            break;
        case "5";
            $res = 'jl';
            break;
        case "6";
            $res = 'xf';
            break;
        default :
            $res = '';
            break;
    }
    return $res;
}

//获取会员卡信息变动原因
function getcardusreason($arr)
{
    switch ($arr) {
        case "1";
            $res = '消费赠送';
            break;
        case "2";
            $res = '充值赠送';
            break;
        case "3";
            $res = '充值到账';
            break;
        case "4";
            $res = '激活赠送';
            break;
        case "5";
            $res = '等级赠送';
            break;
        case "6";
            $res = '分享赠送';
            break;
        case "7";
            $res = '同步赠送';
            break;
        case "19";
            $res = '核销使用';
            break;
        case "11";
            $res = '积分兑换';
            break;
        default;
            $res = '未知';
            break;
    }
    return $res;
}

//获取会员卡信息变动类别
function getcarduscate($arr)
{
    switch ($arr) {
        case "1";
            $res = '积分';
            break;
        case "2";
            $res = '余额';
            break;
        case "3";
            $res = '积分/余额';
            break;
        default;
            $res = '未知';
            break;
    }
    return $res;
}

//获取会员卡信息变动来源
function getcardussource($arr)
{
    switch ($arr) {
        case "1";
            $res = 'WEB后台';
            break;
        case "2";
            $res = '在线充值';
            break;
        case "3";
            $res = '扫码支付';
            break;
        case "4";
            $res = 'APP';
            break;
        case "9";
            $res = '客户端';
            break;
        case "8";
            $res = '小程序';
            break;
        case "7";
            $res = '奖励';
            break;
        case "11";
            $res = '积分商城';
            break;
        default;
            $res = '未知';
            break;
    }
    return $res;
}

//会员卡使用频次
function get_cardus_frequency($openid)
{
    $cardupdate = new \app\common\model\CardUserUpdate();
    $map['openid'] = $openid;
    $map['add_balance|del_balance'] = ['neq', 0];
    $sum = $cardupdate->where($map)->count('id');
    return $sum;
}

//会员卡使用频次(支付宝)
function get_alicards_frequency($user_id, $template_id)
{
    $cardupdate = new \app\common\model\CardUserUpdateAli();
    $map['user_id'] = $user_id;
    $map['template_id'] = $template_id;
    $map['add_balance|del_balance'] = ['neq', 0];
    $sum = $cardupdate->where($map)->count('id');
    return $sum;
}

//获取card_id
function get_card_id($mid)
{
    $CardMember = new \app\common\model\CardMember();
    $Merchant = new \app\common\model\Merchant();
    $top_mid = $Merchant->where(['id' => $mid])->value('top_mid');
    $card_id = $CardMember->where(['top_mid' => $top_mid])->value('card_id');
    return $card_id;
}

//获取会员卡号   充值记录使用
function getcardcode_getid($getid)
{
    $CardUserGet = new \app\common\model\CardUserGet();
    $code = $CardUserGet->where(['id' => $getid])->value('code');
    return $code;
}

//判断购买卡券的库存
function get_is_paycardnum($id)
{
    $CardPaycard = new \app\common\model\CardPaycard();
    $pay = $CardPaycard->where(['id' => $id])->field('num,get_num')->find();
    if ($pay['num'] > $pay['get_num']) {
        $res = true;
    } else {
        $res = false;
    }
    return $res;
}

//判断是否已到最大购买数
function getpaysum($openid, $fid)
{
    $CardPaycard = new \app\common\model\CardPaycard();
    $CardPaycardlog = new \app\common\model\CardPaycardlog();
    $homebuy = $CardPaycard->where(['id' => $fid])->value('homebuy');
    $paynum = $CardPaycardlog->where(['fid' => $fid, 'openid' => $openid, 'paystatu' => 1])->count('id');
    if ($homebuy > $paynum) {
        $res = 0;
    } else {
        $res = 1;
    }
    return $res;
}

//过滤过期
function filterpaycard($startime, $endtime)
{

    $time = time();
    if ($startime < $time) {
        if ($endtime > $time) {
            $res = 0;
//            $res['code'] = 0;
//            $res['msg'] = '正常';
        } else {
            $res = 9001;
//            $res['code'] = 9001;
//            $res['msg'] = '已结束';
        }
    } else {
        $res = 9001;
//        $res['code'] = 9001;
//        $res['msg'] = '未开始';
    }
    return $res;
}

//帮助type
function gethelptype($id)
{
    switch ($id) {
        case "0":
            $res = '微信报错';
            break;
        case "1":
            $res = '会员卡报错';
            break;
        case "2":
            $res = 'API报错';
            break;
        case "3":
            $res = '小程序报错';
            break;
        default:
            $res = '未知类别';
            break;
    }
    return $res;
}

function getusersubscribe($card_id, $openid)
{
    $options = action('mobile/mobilebase/options', array($card_id));
    $weObj = new \Wechat\Wxobjopen($options);
    $user = $weObj->getUserInfo($openid);
    if ($user) {
        if ($user['subscribe'] == 1) {
            $res = "已关注";
        } else {
            $res = "未关注";
        }
    } else {
        $res = $user;
    }
    return $res;

}

//判断是否已到最大领取数
function getfreesum($openid, $fid)
{
    $CardFreecard = new \app\common\model\CardFreecard();
    $CardFreecardlog = new \app\common\model\CardFreecardlog();
    $homebuy = $CardFreecard->where(['id' => $fid])->value('homebuy');
    $paynum = $CardFreecardlog->where(['fid' => $fid, 'openid' => $openid])->count('id');
    if ($homebuy > $paynum) {
        $res = 0;
    } else {
        $res = 1;
    }
    return $res;
}

function getpaycard($arr)
{
    $arr = json_decode($arr, JSON_UNESCAPED_UNICODE);
    $CardGeneral = new \app\common\model\CardGeneral();
    if (is_array($arr)) {
        foreach ($arr as $k => $v) {
            if (isset($v['card_id']) && $v['code']) {
                $datas[$k] = '卡券：' . $CardGeneral->where(['card_id' => $v['card_id']])->value('title') . '[' . $v['code'] . ']';
            } else {
                $datas = [''];
            }
        }
    } else {
        $datas = [''];
    }
    if ($datas) {
        $data = implode(',', $datas);
    } else {
        $data = '';
    }
    return $data;
}

//错误代码翻译
function translate($arr)
{
    $map['code'] = $arr;
    $Translate = new \app\common\model\Translate();
    $info = $Translate->where($map)->value('info');
    if ($info) {
        $msg = $info;
    } else {
        $msg = $arr;
    }
    return $msg;


}

//计算手续费 四舍五入六取整
function service_changes($num, $precision)
{
    $pow = pow(10, $precision);
    //判断不进1的情况（五后为0且为奇）
    if ((floor($num * $pow * 10) % 5 == 0) && (bccomp(floor($num * $pow * 10), $num * $pow * 10) == 0) && (floor($num * $pow) % 2 == 0)) {
        return floor($num * $pow) / $pow;
    } else {
        return round($num, $precision);
    }
}

//判断是否为合法json
function is_json($string)
{
    json_decode($string);
    return (json_last_error() == JSON_ERROR_NONE);
}


function getcmmbpaysignature($post_data, $key)
{

    ksort($post_data);

    $o = "";
    foreach ($post_data as $k => $v) {
        $o .= "$k=" . ($v) . "&";
    }
    $post_data = substr($o, 0, -1);
    $post_data_temp = $post_data . $key;
    $signIn = strtoupper(md5($post_data_temp));
    return $signIn;

}

//卡券抵扣详情
function getdeduzkinfo($arr, $card_zk)
{
    $arr = json_decode($arr, true);
    $CardGeneral = new \app\common\model\CardGeneral();
    if (is_array($arr)) {
        foreach ($arr as $k => $v) {
            if (isset($v['card_id'])) {
                $datas[$k] = $CardGeneral->where(['card_id' => $v['card_id']])->value('title');
            } else {
                $datas = [];
            }
        }
    } else {
        $datas = [];
    }

    if ($datas) {
        $data = implode(',', $datas) . '(' . $card_zk . '元)';
    } else {
        $data = NULL;
    }
    return $data;
}

//会员卡折扣详情
function getdiszkinfo($dis_zk)
{
    if ($dis_zk && $dis_zk > 0) {
        $data = '会员卡折扣:' . $dis_zk . '元';
    } else {
        $data = '';
    }
    return $data;
}

//会员等级折扣详情
function getvipzkinfo($vip_zk)
{
    if ($vip_zk && $vip_zk > 0) {
        $data = '会员等级折扣:' . $vip_zk . '元';
    } else {
        $data = '';
    }
    return $data;
}


function _unsetNull($arr){
    if($arr !== null){
        if (is_object($arr)){
            $arr = json_encode($arr,JSON_UNESCAPED_UNICODE);
            $arr = json_decode($arr,true);
        }
        if(is_array($arr)){
            if(!empty($arr)){
                foreach($arr as $key => $value){
                    if($value === null){
                        $arr[$key] = '';
                    }else{
                        $arr[$key] = _unsetNull($value);      //递归再去执行
                    }
                }
            }
        }else{
            if($arr === null){ $arr = ''; }         //注意三个等号
        }
    }else{ $arr = ''; }
    return $arr;
}